#include "comm.hpp"

int main()
{
    // 创建共享内存
    int shmid = CreateMem();
    log(Debug, "create sharemem done...");

    sleep(5);

    // 挂接共享内存
    char *shmaddr = (char*)shmat(shmid, nullptr, 0);
    log(Debug, "attach shm done, shmaddr: 0x%x", shmaddr);

    sleep(5);

    // ipc-cod 通信代码
    while(true)
    {
        cout << "client asy@ " << shmaddr << endl; // 直接访问共享内存
        sleep(1);
    }

    // 去关联
    shmdt(shmaddr);
    log(Debug, "detach shm done, shmaddr: 0x%x", shmaddr);

    sleep(5);

    // 释放共享内存
    shmctl(shmid, IPC_RMID, nullptr);
    log(Debug, "destory shm done, shmaddr: 0x%x", shmaddr);

    sleep(5);

    log(Debug, "processa quit...");
    return 0;
}
